package A05_栈;

/**
 * @Author: KingWang
 * @Date: 2021/6/1
 * @Desc:
 **/
public class Calculate{

    private Stack<Integer> numStack;
    private Stack<Integer> operStack;
    private int maxSize = 100;

    public Calculate(int size) {
        numStack = new Stack<>(maxSize);
        operStack = new Stack<>(maxSize);
    }

    //运算符优先级判断
    public int priority(int oper){
        if("*/".indexOf(oper) > 0){
            return 1;
        }else if("+-".indexOf(oper) > 0){
            return 0;
        }else{
            return -1;
        }
    }

    public boolean isOper(int oper){
        return "+-*/".indexOf(oper) > 0;
    }

    public int calc(int a,int b,int oper){
        int result = 0;
        switch (oper){
            case '+': result = a + b;break;
            case '-': result = a - b;break;
            case '*': result = a * b;break;
            case '/': result = a / b;break;
        }
        return result;
    }



}
